package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spec")
public class SpecGroupController {
    @Autowired
    private SpecGroupService specGroupService;
    @GetMapping("groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroupById(@RequestParam("id") Long id){
        return ResponseEntity.ok(this.specGroupService.querySpecGroupById(id));
    }
    @GetMapping("params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParamByGid(@RequestParam(value = "gid",required = false) Long gid,
                                                                  @RequestParam(value = "cid",required = false) Long cid,
                                                                  @RequestParam(value = "searching",required = false) Boolean searching){
        return ResponseEntity.ok(this.specGroupService.querySpecParamByGid(gid,cid,searching));
    }
    @PostMapping("group")
    public ResponseEntity<Void> addSpecGroup(@RequestBody SpecGroupDTO specGroupDTO){
        this.specGroupService.addSpecGroup(specGroupDTO);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
    @PutMapping("group")
    public ResponseEntity<Void> editSpecGroup(@RequestBody SpecGroupDTO specGroupDTO){
        this.specGroupService.editSpecGroup(specGroupDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
    @DeleteMapping("group")
    public ResponseEntity<Void> deleteById(@RequestParam("id")Long id){
        this.specGroupService.deleteById(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
    @PostMapping("param")
    public ResponseEntity<Void> addSpecParam(@RequestBody SpecParamDTO specParamDTO){
        this.specGroupService.addSpecParam(specParamDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
    @PutMapping("param")
    public ResponseEntity<Void> editSpecParam(@RequestBody SpecParamDTO specParamDTO){
        this.specGroupService.editSpecParam(specParamDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
    @DeleteMapping("param")
    public ResponseEntity<Void> deleteSpecParamById(@RequestParam("id") Long id){
        this.specGroupService.deleteSpecParamById(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

}
